package basics.loops;

import java.util.Scanner;
public class BankBalanceVaryingInterest
{
   public static void main(String[] args)
   {
      double balance;
      String response;
      char responseChar;
      int tempBalance;
      int year = 1;
      double interest;
      final double LOW = 0.02;
      final double HIGH = 0.05;
      final double INT_INCREMENT = 0.01;
      Scanner keyboard = new Scanner(System.in);
       System.out.print("Enter initial bank balance > ");
      balance = keyboard.nextDouble();
      keyboard.nextLine();
      System.out.println("Do you want to see next year's balance?");
      System.out.print("Enter y or n > ");
      response = keyboard.nextLine();
      responseChar = response.charAt(0);
      while(responseChar == 'y')
      {
         for(interest = LOW; interest <= HIGH; interest += INT_INCREMENT)
         {
            balance = balance + balance * interest;
            tempBalance = (int)(balance * 100);
            balance = tempBalance / 100.0;
            System.out.println("After year " + year + " at " +  interest +
               " interest rate, balance is $" + balance);
         }
            year = year + 1;
            System.out.print("Do you want to see the balance " +
               "\nat the end of another year? y or n? >");
            response = keyboard.nextLine();
            responseChar = response.charAt(0);
      }
   }
}
